import request from './request.js';
import { setToken } from './token.js';
import { getUserInfo } from './user.js';

// 微信登录
export const loginWithWeChat = async (code) => {
  const res = await request({
    url: '/auth/login/wechat',
    method: 'POST',
    data: { code }
  });
  
  if (res.token) {
    setToken(res.token);
  }
  return res;
};

// 支付宝登录（预留）
export const loginWithAlipay = async (code) => {
  const res = await request({
    url: '/auth/login/alipay', // 预留的支付宝登录接口
    method: 'POST',
    data: { code }
  });
  
  if (res.token) {
    setToken(res.token);
    // 获取用户信息
    await getUserInfo();
  }
  return res;
};

// 分享奖励
export const shareReward = async (data) => {
  const res = await request({
    url: '/auth/share/reward',
    method: 'POST',
    data
  });
  return res;
};